from django.db import models
from django.contrib.auth.models import User
from django.contrib import admin
from django.contrib.auth.utils import get_hexdigest
from forfood.address.models import Address

url = "http://127.0.0.1:8000/"
class Customer(User):
    name = models.CharField(max_length=10)
    phone = models.CharField(max_length=15)
    address = models.ForeignKey(Address)
    def __unicode__(self):
        return self.username     
    def get_manage_path(self):
        return "/"
    def make_email_code(self):
        return "%s"%get_hexdigest('sha1', self.username, self.id)
    def make_verification_address(self):
        addr = "%sverify/%d/%s"%(url,self.id,self.make_email_code())
    def activate(self,code):
        c = "%s"%get_hexdigest('sha1', self.username, self.id)
        print c
        if code == c:
            return True
        else:
            return False
    def get_orders(self):
        return self.order_set.all()
    
    def get_address(self):
        if self.address.more == "None":
            return None
        else:
            return self.address.get_full_address()
class CustomerAdmin(admin.ModelAdmin):
    pass
admin.site.register(Customer, CustomerAdmin)   
